package com.itlong.cloud.sdk.service.impl;

import com.itlong.cloud.POJO.DTO.property.PropertyAddVisitorDTO;
import com.itlong.cloud.POJO.DTO.property.PropertyGetVisitorInfoDTO;
import com.itlong.cloud.POJO.VO.sdk.SDKFaceVisitorInfoVO;
import com.itlong.cloud.sdk.dao.IFaceSDKVisitorPassCodeRecordDao;
import com.itlong.cloud.sdk.service.IFaceSDKVisitorPassCodeRecordService;
import com.itlong.cloud.utils.data.handler.SqlUtil;
import com.itlong.cloud.utils.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
* <desc>
*      人脸识别API-访客业务处理接口
* </desc>
*
* @createDate 2019/11/11
*/
@Service
public class FaceSDKVisitorPassCodeRecordServiceImpl implements IFaceSDKVisitorPassCodeRecordService {

    @Autowired
    IFaceSDKVisitorPassCodeRecordDao iFaceSDKVisitorPassCodeRecordDao;


    /**
     * <desc>
     *     访客列表
     * <desc/>
     *
     *@param  visitorInfoDTO  分页查询访客列表
     * @return  MessageVO 标准格式化响应结果
     * @author JuGuang.S
     * @createDate 2019/11/11
     */
    @Override
    public Page<SDKFaceVisitorInfoVO> getVisitorInfoForFaceApi(PropertyGetVisitorInfoDTO visitorInfoDTO) throws Exception {
        Map<String, Object> params = SqlUtil.convertBeanToMapParams(visitorInfoDTO);
        params.put("projectId", visitorInfoDTO.getProjectId());

        Page<SDKFaceVisitorInfoVO> page = new Page<>();
        page.getPage().setPageSize(visitorInfoDTO.getPageSize());
        page.getPage().setCurrentPage(visitorInfoDTO.getCurrentPage());
        params.put("currentPage", page.getPage().getStartSlip());
        params.put("pageSize", page.getPage().getPageSize());

        List<SDKFaceVisitorInfoVO> visitorInfoList = iFaceSDKVisitorPassCodeRecordDao.getVisitorInfoByPage(params);
        for(SDKFaceVisitorInfoVO infoVO : visitorInfoList){
           String adressName = iFaceSDKVisitorPassCodeRecordDao.getAdressByRoomId(infoVO.getRoomId());
           infoVO.setAddress(adressName);
        }
        Integer count = iFaceSDKVisitorPassCodeRecordDao.getVisitorInfoCount(params);

        page.setRows(visitorInfoList, count);
        return page;
    }

    /**
     * <desc>
     *     校验地址是否真实存在
     * <desc/>
     *
     * @param  visitorInfoDTO  校验条件
     * @return 楼栋单元房间编号ID
     * @author JuGuang.S
     * @createDate 2019/11/18
     */
    @Override
    public Map<String,Object> getAddressInfo(PropertyAddVisitorDTO visitorInfoDTO) throws Exception {
        return iFaceSDKVisitorPassCodeRecordDao.getAddressInfo(visitorInfoDTO);
    }

}
